package sz.szsmk.citizencard.ui.adapter;

import androidx.recyclerview.widget.RecyclerView;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import java.util.List;

import sz.szsmk.citizencard.R;
import sz.szsmk.citizencard.model.network.bean.response.QueryMetroExitInfoRes;
import sz.szsmk.citizencard.ui.activity.SubwaySiteDetailActivity;

/**
 * Copyright (c)2018
 * author: zdh
 * created on: 2018/12/11 10:36
 * description:
 */
public class SubwaySiteInfoAdapter extends RecyclerView.Adapter<SubwaySiteInfoAdapter.SubwaySiteHolder> {
    private SubwaySiteDetailActivity mContext;
    private  List<QueryMetroExitInfoRes.MetroExtraInfoListBean.MetroLineListBean> viewData;

    public SubwaySiteInfoAdapter(SubwaySiteDetailActivity context) {
        mContext = context;
    }

    @Override
    public SubwaySiteHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(mContext).inflate(R.layout.item_subwaydetail_lines, parent, false);
        return new SubwaySiteHolder(view);
    }

    @Override
    public void onBindViewHolder(SubwaySiteHolder holder, int position) {
        if (viewData != null) {
           QueryMetroExitInfoRes.MetroExtraInfoListBean.MetroLineListBean metroLineListBean =viewData.get(position);
            if(TextUtils.isEmpty(metroLineListBean.getDrive_start())){
                holder.lin_start.setVisibility(View.GONE);
                holder.view_lines.setVisibility(View.GONE);
            }else{
                holder.lin_start.setVisibility(View.VISIBLE);
                holder.view_lines.setVisibility(holder.lin_end.getVisibility());
            }
            if(TextUtils.isEmpty(metroLineListBean.getDrive_end())){
                holder.lin_end.setVisibility(View.GONE);
                holder.view_lines.setVisibility(View.GONE);
            }else{
                holder.lin_end.setVisibility(View.VISIBLE);
                holder.view_lines.setVisibility(holder.lin_start.getVisibility());
            }


            holder.xlname.setText(metroLineListBean.getLine_name());
            holder.qdname1.setText(metroLineListBean.getDrive_start());
            holder.qdtime1.setText(metroLineListBean.getStart_first_time());
            holder.zdtime1.setText(metroLineListBean.getStart_last_time());
            holder.qdtime2.setText(metroLineListBean.getEnd_first_time());
            holder.zdtime2.setText(metroLineListBean.getEnd_last_time());
            holder.zdname1.setText(metroLineListBean.getDrive_end());
        }
    }

    @Override
    public int getItemCount() {
        return null == viewData ? 0 : viewData.size();
    }

    public void setViewData(  List<QueryMetroExitInfoRes.MetroExtraInfoListBean.MetroLineListBean> viewData) {
        this.viewData = viewData;
    }

    public static class SubwaySiteHolder extends RecyclerView.ViewHolder {


        private final TextView xlname;
        private final TextView qdname1;
        private final TextView zdname1;
        private final TextView qdtime1;
        private final TextView zdtime1;
        private final TextView qdtime2;
        private final TextView zdtime2;
        private final LinearLayout lin_start;
        private final LinearLayout lin_end;
        private final View view_lines;
        public SubwaySiteHolder(View itemView) {
            super(itemView);
            lin_start = (LinearLayout) itemView.findViewById(R.id.lin_start);
            lin_end = (LinearLayout) itemView.findViewById(R.id.lin_end);
            xlname = (TextView) itemView.findViewById(R.id.xlname);
            qdname1 = (TextView) itemView.findViewById(R.id.subway_site_detail_start);
            zdname1 = (TextView) itemView.findViewById(R.id.subway_site_detail_end);
            qdtime1 = (TextView) itemView.findViewById(R.id.subway_detail_time_start);
            zdtime1 = (TextView) itemView.findViewById(R.id.subway_detail_time_end);
            qdtime2 = (TextView) itemView.findViewById(R.id.subway_detail_time_end_start);
            zdtime2 = (TextView) itemView.findViewById(R.id.subway_detail_time_end_end);
            view_lines= itemView.findViewById(R.id.view_lines);
//            TextView textView = (TextView) itemView.findViewById(R.id.text_1);
        }
    }

}
